package lion.json.handlers;

import java.io.IOException;
import java.io.Writer;

import lion.json.IJsonHandler;

/**
 * @author lion
 * @mail hl_0074@sina.com
 * @date 2011-10-24
 */
public class BooleanHandler implements IJsonHandler {

	@Override
	public void handle(Object o, Writer write) throws IOException {

		boolean result = false;

		if (o != null) {
			if (o instanceof Boolean) {
				result = ((Boolean) o).booleanValue();
			} else {
				String tmp = String.valueOf(o);
				if ("on".equals(tmp) || "true".equals(tmp) || "1".equals(tmp)) {
					result = true;
				}
			}
		}
		write.write(String.valueOf(result));
	}
}
